class Solution {
public:
    int minNumberOfFrogs(string croakOfFrogs) {
        unordered_map <char,int> hash(100);
        int n=croakOfFrogs.size();
        if(n%5!=0) return -1;
        for(int i=0;i<n;++i)
        {
            if(croakOfFrogs[i]=='c'&&hash['k']>=1)
            {
                hash['c']++;
                hash['k']--;
            }

            else if(croakOfFrogs[i]=='c')
            {
                hash['c']++;
            }

            else if(croakOfFrogs[i]=='r')
            {
                hash['r']++;
                hash['c']--;
                if( hash['c']<0) return -1;
            }

            else if(croakOfFrogs[i]=='o')
            {
                hash['o']++;
                hash['r']--;
                if( hash['r']<0) return -1;
            }

            else if(croakOfFrogs[i]=='a')
            {
                hash['a']++;
                hash['o']--;
                if( hash['o']<0) return -1;
            }

            else if(croakOfFrogs[i]=='k')
            {
                hash['k']++;
                hash['a']--;
                if(  hash['a']<0) return -1;
            }
        }
        if (hash['c']!=0||hash['r']!=0||hash['o']!=0||hash['a']!=0) 
        {
            return -1;
        }
        return hash['k'];
    }
};
